#include<iostream>
using namespace std;
const int N = 1e7 + 10;
int primes[N], cnt;
bool st[N];
int arr[N];
void get_prime()
{
	int n = 1e7 + 3;
	for (int i = 2; i <= n; i++) {
		if (!st[i])primes[++cnt] = i;
		for (int j = 1; primes[j] <= n / i; j++) {
			st[primes[j] * i] = 1;
			if (i % primes[j] == 0)break;
		}
	}
}
bool check(int x)
{
	int t = x;
	int ans = 0;
	while (x) {
		ans = ans * 10 + x % 10;
		x /= 10;
	}
	return t == ans ? 1 : 0;
}
int main()
{
	get_prime();
	//cout << cnt << endl;
	int m = 0;
	for (int i = 1; i <= cnt; i++) {
		if (check(primes[i])) {
			arr[++m] = primes[i];
		}
	}
	int a = 0, b = 0;
	while (cin >> a >> b) {
		/*int ans1 = 0, ans2 = 0;
		int l = 0, r = m + 1;
		while (l + 1 < r) {
			int mid = (l + r) >> 1;
			if (arr[mid] < a)l = mid;
			else r = mid;
		}
		ans1 = r;
		l = 0, r = m + 1;
		while (l + 1 < r) {
			int mid = (l + r) >> 1;
			if (arr[mid] <= b)l = mid;
			else r = mid;
		}
		ans2 = l;
		for (int i = ans1; i <= ans2; i++) {
			cout << arr[i] << endl;
		}*/
		for (int i = 1; i <= m; i++) {
			if (arr[i] >= a && arr[i] <= b)printf("%d\n", arr[i]);
		}
		cout << endl;
	}
	return 0;
}